﻿using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;
using Microsoft.Office.PowerPoint.STAMP.Core;
using NUnit.Framework;
using Shape = Microsoft.Office.Interop.PowerPoint.Shape;

namespace Microsoft.Office.PowerPoint.STAMP.Test
{
    [TestFixture]
    public class ShapeFinderTest
    {
        private Application _app;

        [SetUp]
        public void TestInitialise()
        {
            _app = new Application();
            _app.Presentations.Add(MsoTriState.msoFalse);
            _app.Presentations[1].Slides.Add(1, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutBlank);
        }

        [TearDown]
        public void TestCleanup()
        {
            _app.Presentations[1].Close();
            _app.Quit();
            _app = null;
        }

        [Test]
        public void LocateShapesWhenOnSlide()
        {
            var slide = _app.Presentations[1].Slides[1];

            var s = slide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 1, 1, 100, 50);
            s.Name = "Media1 Shape 1";
            s = slide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 1, 1, 100, 50);
            s.Name = "Media1 Shape 2";
            s = slide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 1, 1, 100, 50);
            s.Name = "MediaX Shape 2";

            var foundShapes = ShapeFinder.FindShapesByMediaName(slide, "Media1");

            Assert.AreEqual(3, slide.Shapes.Count);
            Assert.AreEqual(2, foundShapes.Count);
        }

        [Test]
        public void SlideWithNoShapesDoesntError()
        {
            var slide = _app.Presentations[1].Slides[1];

            var foundShapes = ShapeFinder.FindShapesByMediaName(slide, "Media1");

            Assert.AreEqual(0, slide.Shapes.Count);
            Assert.AreEqual(0, foundShapes.Count);
        }

        [Test]
        public void LocateNoShapesWhenNameNotMatched()
        {
            var slide = _app.Presentations[1].Slides[1];

            var s = slide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 1, 1, 100, 50);
            s.Name = "Media1 Shape 1";
            s = slide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 1, 1, 100, 50);
            s.Name = "Media1 Shape 2";
            s = slide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 1, 1, 100, 50);
            s.Name = "Media2 Shape 1";

            var foundShapes = ShapeFinder.FindShapesByMediaName(slide, "NotMatched");

            Assert.AreEqual(3, slide.Shapes.Count);
            Assert.AreEqual(0, foundShapes.Count);
        }

        [Test()]
        public void DetermineShapeSizeTest()
        {
            var slide = _app.Presentations[1].Slides[1];

            RectangleF slideRectangle = new RectangleF(0, 0, 1000, 1000);
            RectangleF mediaRectangle = new RectangleF(0, 0, 500, 500);
            CaptionStyle style = new CaptionStyle();

            var SizeF = Utils.DetermineShapeSize(slideRectangle, mediaRectangle, style, "jamie mclean is goodjamie mclean is goodjamie mclean is goodjamie mclean is good", slide);

            Assert.AreEqual(1, 1);
        }
    }
}
